import React, { Component } from 'react'
import tx from '../../../assets/images/avatar.png'
export default class Form extends Component {
  state = {
    // 文本框内容
    texts: '',
  }
  // 发布评论
  // 获取文本框内容
  getTexts = (e) => {
    this.setState({
      texts: e.target.value,
    })
    // console.log(e.target.value)
  }
  add = () => {
    if (!this.state.texts.trim()) return this.setState({ texts: '' })
    this.props.publish(this.state.texts)
    this.setState({
      texts: '',
    })
  }
  render() {
    return (
      <div className="comment-send">
        <div className="user-face">
          <img className="user-head" src={tx} alt="" />
        </div>
        <div className="textarea-container">
          <textarea
            cols="80"
            rows="5"
            placeholder="发条友善的评论"
            className="ipt-txt"
            value={this.state.texts}
            onChange={this.getTexts}
          />
          <button className="comment-submit" onClick={this.add}>
            发表评论
          </button>
        </div>
        <div className="comment-emoji">
          <i className="face"></i>
          <span className="text">表情</span>
        </div>
      </div>
    )
  }
}
